package com.neusoft.controller;

import com.neusoft.common.Result;
import com.neusoft.pojo.Dict;
import com.neusoft.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dict")
public class DictController {

    @Autowired
    DictService dictService;

    /**
     * 查询所有的字典表
     * @return 返回集合
     */
    @GetMapping
    public Result<?> queryDictAll(){
        List<Dict> dictAll = dictService.selectDictAll();
        return Result.success(dictAll);
    }

    @PostMapping
    public Result<?> addDict(@RequestBody Dict dict){
        int s = dictService.insertDict(dict);
        if (1 == s) {
            return Result.success("字典插入成功");
        }else {
            return Result.error("200","字典插入失败");
        }
    }

    @DeleteMapping("/{dictId}")
    public Result<?> removeDict(@PathVariable String dictId){
        int s = dictService.deleteDict(dictId);
        if (1 == s) {
            return Result.success("字典删除成功");
        }else {
            return Result.error("200","字典删除失败");
        }
    }
}
